' DEMO for the "Passed Arrays" bug
' this DEMO works with MMBasic V5.0(.0) (the first one) perfektly!
'
' With MMBasic 5.04.5:
' this DEMO works after EDIT + RUN (F2 in the editor)
' BUT it crashes after a second (CTRL+C) + RUN
' Error message:
'   [53] M=s(i):s(i)=s(h):s(h)=M
'   Error: String too long
'----------------------------------------------------

Option base 0
Dim integer min=1, max = 200
Dim string q(max) length 10, qo

For n = min To max
   q(n)=Str$(Rnd()*10000, 6, 2)
   Print n,q(n)
   Next

   Timer= 0
   sCombSort q(), min, max
   tx= Timer/1000

   qo=""
   For n = min To max
     Print "#"n,q(n)
     If q(n)<qo Then Print" error":End
     qo=q(n)
   Next
   Print
   Print tx "sec"
End

'-----------------------------------------------------------------
' Comb Sort for strings v1.02
' an optimized (8/2017 by twofingers@TBS) version of aCombSort for strings.
' It sorts the array S() and needs the number of elements to sort (STop)
' System: MM2/MMBasic 5.04.05
' String array is passed by reference
'
Sub sCombSort (S() As string, Start As integer, STop As integer)
Local M As string
Local integer i, h, sw, G=STop
Local Shrink=1.3
Do While G>1 Or Sw
G=G/Shrink-0.1
If Not G Then G=1
i=Start
Sw=0
For h=i+G To STop
If s(i)>s(h)Then
M=s(i):s(i)=s(h):s(h)=M
Sw=1
EndIf
i=i+1
Next
Loop
End Sub                              